package com.pig4cloud.pig.admin.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.pig4cloud.pig.admin.api.dto.BindRfidDto;
import com.pig4cloud.pig.admin.api.entity.*;
import com.pig4cloud.pig.admin.api.vo.UserVO;
import com.pig4cloud.pig.admin.emqx.dto.EmqxClientQueryDto;
import com.pig4cloud.pig.admin.emqx.openapi.EmqxFeignClient;
import com.pig4cloud.pig.admin.emqx.vo.EmqxDataVo;
import com.pig4cloud.pig.admin.emqx.vo.MqttClientStats;
import com.pig4cloud.pig.admin.mapper.PrRfidMapper;
import com.pig4cloud.pig.admin.mapper.SysUserMapper;
import com.pig4cloud.pig.admin.mq.MqttMessageSender;
import com.pig4cloud.pig.admin.mq.vo.*;
import com.pig4cloud.pig.admin.service.*;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 标签管理
 *
 * @author pig
 * @date 2025-06-08 20:10:38
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/prRfid" )
@Tag(description = "prRfid" , name = "标签管理管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PrRfidController {

	private final PrRfidMapper prRfidMapper;
    private final PrRfidService prRfidService;
    private final PrDeviceService prDeviceService;
    private final MqttMessageSender mqttMessageSender;
    private final SysUserMapper sysUserMapper;
    private final SysUserService sysUserService;
    private final PrUserService prUserService;
	@Value("${spring.mqtt.devTopic}")
	private String devTopic;
	@Resource
	private EmqxFeignClient emqFeignClient;
    /**
     * 分页查询
     * @param page 分页对象
     * @param prRfid 标签管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('admin_prRfid_view')" )
    public R getPrRfidPage(@ParameterObject Page<PrRfidEntity> page, @ParameterObject PrRfidEntity prRfid) {
        LambdaQueryWrapper<PrRfidEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(StrUtil.isNotBlank(prRfid.getDeviveName()),PrRfidEntity::getDeviveName,prRfid.getDeviveName());
		wrapper.eq(null != prRfid.getDeviceId(),PrRfidEntity::getDeviceId,prRfid.getDeviceId());
		wrapper.eq(StrUtil.isNotBlank(prRfid.getRfidName()),PrRfidEntity::getRfidName,prRfid.getRfidName());
		wrapper.eq(StrUtil.isNotBlank(prRfid.getRfidStatus()),PrRfidEntity::getRfidStatus,prRfid.getRfidStatus());
		wrapper.orderByAsc(PrRfidEntity::getDeviceSign,PrRfidEntity::getRfidColumn);
		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());

		Page<PrRfidEntity> rtPage = prRfidService.page(page, wrapper);
		rtPage.getRecords().forEach(item -> {
			if(clientIdList.contains(item.getDeviceSign())){
				item.setOnline("在线");
				item.setEnabled(Boolean.TRUE);
			}else{
				item.setOnline("离线");
				item.setEnabled(Boolean.FALSE);
			}
		});
		return R.ok(rtPage);
    }
	/**
	 * 标签预览分页
	 * @param page 分页对象
	 * @param prRfid 标签预览
	 * @return
	 */
	@Operation(summary = "标签预览" , description = "标签预览" )
	@GetMapping("/view/page" )
	public R getPrRfidViewPage(@ParameterObject Page<PrRfidEntity> page, @ParameterObject PrRfidEntity prRfid) {

		//获取当前用户绑定的柜体用户
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(SysUser::getUsername, authentication.getName());
		SysUser user = sysUserService.getOne(queryWrapper);
		UserVO userVO = sysUserMapper.getUserVoById(user.getUserId());
		JSONArray prUser = userVO.getPrUser();
		if(CollUtil.isEmpty(prUser)){
			return R.failed("当前用户未绑定柜体");
		}
		//用户id标识
		Set<String> userIdList = new HashSet<>();
		//柜体标识
		Set<String> signList = new HashSet<>();
		for (int i = 0; i < prUser.size(); i++) {
			JSONArray pu = prUser.getJSONArray(i);
			userIdList.add(pu.getString(1));
			signList.add(pu.getString(0));
		}

		//连表查询当前用户绑定柜体的钥匙标签
		MPJLambdaWrapper<PrRfidEntity> mapper = new MPJLambdaWrapper<>();
		mapper.selectAll(PrRfidEntity.class)
				.selectCollection(PrUserRfidInfoEntity.class, PrRfidEntity::getPrUserRfidInfoEntities)
				.leftJoin(PrUserRfidInfoEntity.class,
						on -> {
							on.eq(PrUserRfidInfoEntity::getGoodsId, PrRfidEntity::getGoodsId)
							.eq(PrUserRfidInfoEntity::getDeviceSign, PrRfidEntity::getDeviceSign);
							return on;
						})
				.in(PrUserRfidInfoEntity::getUserId, userIdList)
				.in(PrUserRfidInfoEntity::getDeviceSign, signList)
				.like(StringUtils.isNotBlank(prRfid.getRfidName()),PrRfidEntity::getRfidName,prRfid.getRfidName())
				.like(StringUtils.isNotBlank(prRfid.getDeviveName()),PrRfidEntity::getDeviveName,prRfid.getDeviveName())
				.eq(StringUtils.isNotBlank(prRfid.getRfidStatus()),PrRfidEntity::getRfidStatus,prRfid.getRfidStatus())
				.orderByAsc(PrRfidEntity::getDeviceSign).orderByAsc(PrRfidEntity::getRfidColumn);
		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());


		Page<PrRfidEntity> rtPage = prRfidMapper.selectPage(page, mapper);
		rtPage.getRecords().forEach(rt -> {
			if(clientIdList.contains(rt.getDeviceSign())){
				rt.setOnline("在线");
				rt.setEnabled(Boolean.TRUE);
			}else{
				rt.setOnline("离线");
				rt.setEnabled(Boolean.FALSE);
			}
		});
		return R.ok(rtPage);
	}


	/**
	 * 列表
	 * @param prRfid 标签管理
	 * @return
	 */
	@Operation(summary = "列表" , description = "列表" )
	@GetMapping("/list" )
	@PreAuthorize("@pms.hasPermission('admin_prRfid_view')" )
	public R list(@ParameterObject PrRfidEntity prRfid) {
		MPJLambdaWrapper<PrRfidEntity> wrapper = new MPJLambdaWrapper<PrRfidEntity>()
				.selectAll(PrRfidEntity.class)
				.selectCollection(PrUserRfidInfoEntity.class, PrRfidEntity::getPrUserRfidInfoEntities)
				.leftJoin(PrUserRfidInfoEntity.class,
						on -> {
							on.eq(PrUserRfidInfoEntity::getGoodsId, PrRfidEntity::getGoodsId);
							on.eq(PrUserRfidInfoEntity::getUserId,prRfid.getUserId());
							return on;
						});
		wrapper.eq(null != prRfid.getDeviceId(), PrRfidEntity::getDeviceId, prRfid.getDeviceId());
		JSONObject jsonObject = new  JSONObject();
		jsonObject.put("records", prRfidMapper.selectJoinList(PrRfidEntity.class,wrapper));
		return R.ok(jsonObject);
	}

	/**
	 * 设备用户绑定
	 * @return
	 */
	@PostMapping("bind")
	public R bind(@RequestBody BindRfidDto bindRfidDto){
		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());
		if(!clientIdList.contains(bindRfidDto.getDeviceSign())){
			return R.result(null,500,"当前设备不在线");
		}
		//
		UserBindRfidVo userBindRfidVo = new UserBindRfidVo();

		List<String> goodsIds = new ArrayList<>();
		goodsIds.add(bindRfidDto.getGoodsId());
		//获取当前用户绑定的柜体用户
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(SysUser::getUsername, authentication.getName());
		SysUser user = sysUserService.getOne(queryWrapper);
		UserVO userVO = sysUserMapper.getUserVoById(user.getUserId());
		JSONArray prUser = userVO.getPrUser();
		if(null == prUser){
			return R.result(null,500,"当前用户未绑定柜体");
		}
		String userId = "";
		for (int i = 0; i < prUser.size(); i++) {
			JSONArray pu = prUser.getJSONArray(i);
			String deviceSign = pu.getString(0);
			if(bindRfidDto.getDeviceSign().equals(deviceSign)){
				userId = pu.getString(1);
			}

		}
		if(StringUtils.isBlank(userId)){
			return R.result(null,500,"当前用户未绑定柜体");
		}
		userBindRfidVo.setManagerUserId(userId);
		userBindRfidVo.setUserId(bindRfidDto.getUserId());
		userBindRfidVo.setGoodsIds(goodsIds);
		SendRequestVo<UserBindRfidVo> sendRequestVo = new SendRequestVo<>();
		sendRequestVo.setData(userBindRfidVo);
		sendRequestVo.setDeviceid(bindRfidDto.getDeviceSign());
		sendRequestVo.setType("send");
		if(bindRfidDto.getBind()){
			//绑定
			sendRequestVo.setCmdtype("12");
		}else{
			//解绑
			sendRequestVo.setCmdtype("13");
		}
		String tic = String.format(devTopic, bindRfidDto.getDeviceSign());
		mqttMessageSender.send(bindRfidDto.getDeviceSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
		return R.ok();
	}

    /**
     * 通过条件查询标签管理
     * @param prRfid 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    @PreAuthorize("@pms.hasPermission('admin_prRfid_view')" )
    public R getDetails(@ParameterObject PrRfidEntity prRfid) {
        return R.ok(prRfidService.list(Wrappers.query(prRfid)));
    }

    /**
     * 新增标签管理
     * @param prRfid 标签管理
     * @return R
     */
    @Operation(summary = "新增标签管理" , description = "新增标签管理" )
    @SysLog("新增标签管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_prRfid_add')" )
    public R save(@RequestBody PrRfidEntity prRfid) {
        return R.ok(prRfidService.save(prRfid));
    }

    /**
     * 修改标签管理
     * @param prRfid 标签管理
     * @return R
     */
    @Operation(summary = "修改标签管理" , description = "修改标签管理" )
    @SysLog("修改标签管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_prRfid_edit')" )
    public R updateById(@RequestBody PrRfidEntity prRfid) {

		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());
		if(!clientIdList.contains(prRfid.getDeviceSign())){
			return R.result(null,500,"当前设备不在线");
		}

		//通知柜体修改标签信息
		//获取设备sign
		SendRequestVo<UpdateRfidVo> sendRequestVo = new SendRequestVo<UpdateRfidVo>();
		UpdateRfidVo updateRfidVo = new UpdateRfidVo();
		updateRfidVo.setUid(prRfid.getRfidNum());
		updateRfidVo.setGoodsId(prRfid.getGoodsId());
//		updateRfidVo.setAdd(prRfid.getRfidColumn());
//		updateRfidVo.setState(prRfid.getRfidStatus());
		updateRfidVo.setKeyName(prRfid.getRfidName());

		//获取当前用户绑定的柜体用户
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(SysUser::getUsername, authentication.getName());
		SysUser user = sysUserService.getOne(queryWrapper);
		UserVO userVO = sysUserMapper.getUserVoById(user.getUserId());
		JSONArray prUser = userVO.getPrUser();
		if(null == prUser){
			return R.failed("当前用户未绑定柜体");
		}
		String userId = "";
		for (int i = 0; i < prUser.size(); i++) {
			JSONArray pu = prUser.getJSONArray(i);
			String deviceSign = pu.getString(0);
			if(prRfid.getDeviceSign().equals(deviceSign)){
				userId = pu.getString(1);
			}

		}
		updateRfidVo.setUserId(userId);
		sendRequestVo.setData(updateRfidVo);
		sendRequestVo.setDeviceid(prRfid.getDeviceSign());
		sendRequestVo.setType("send");
		sendRequestVo.setCmdtype("10");
		String tic = String.format(devTopic, prRfid.getDeviceSign());
		mqttMessageSender.send(prRfid.getDeviceSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
        return R.ok(prRfidService.updateById(prRfid));
    }

    /**
     * 通过id删除标签管理
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除标签管理" , description = "通过id删除标签管理" )
    @SysLog("通过id删除标签管理" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('admin_prRfid_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(prRfidService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param prRfid 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('admin_prRfid_export')" )
    public List<PrRfidEntity> exportExcel(PrRfidEntity prRfid,Long[] ids) {
        return prRfidService.list(Wrappers.lambdaQuery(prRfid).in(ArrayUtil.isNotEmpty(ids), PrRfidEntity::getId, ids));
    }

    /**
     * 导入excel 表
     * @param prRfidList 对象实体列表
     * @param bindingResult 错误信息列表
     * @return ok fail
     */
    @PostMapping("/import")
    @PreAuthorize("@pms.hasPermission('admin_prRfid_export')" )
    public R importExcel(@RequestExcel List<PrRfidEntity> prRfidList, BindingResult bindingResult) {
        return R.ok(prRfidService.saveBatch(prRfidList));
    }

	/**
	 * 同步钥匙信息
	 * @param deviceId
	 * @return
	 */
	@GetMapping("sync/rfid")
	@SysLog("同步钥匙信息" )
	public R syncRfid(@RequestParam String deviceId) {
		PrDeviceEntity prDeviceEntity = prDeviceService.getById(deviceId);
		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());
		if(!clientIdList.contains(prDeviceEntity.getDevSign())){
			return R.result(null,500,"当前设备不在线");
		}

		//保存当前用户
		//获取设备sign

		SendRequestVo<RfidInfoVo> sendRequestVo = new SendRequestVo<RfidInfoVo>();
		RfidInfoVo rfidInfoVo = new RfidInfoVo();
		sendRequestVo.setData(rfidInfoVo);
		sendRequestVo.setDeviceid(prDeviceEntity.getDevSign());
		sendRequestVo.setType("send");
		sendRequestVo.setCmdtype("18");
		String tic = String.format(devTopic, prDeviceEntity.getDevSign());
		mqttMessageSender.send(prDeviceEntity.getDevSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
		return R.ok();
	}


	/**
	 * 同步用户信息
	 * @param deviceId
	 * @return
	 */
	@GetMapping("sync/user")
	@SysLog("同步用户信息" )
	public R syncUser(@RequestParam String deviceId) {
		//保存当前用户
		//获取设备sign
		PrDeviceEntity prDeviceEntity = prDeviceService.getById(deviceId);

		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());
		if(!clientIdList.contains(prDeviceEntity.getDevSign())){
			return R.result(null,500,"当前设备不在线");
		}


		SendRequestVo<UpdateUserVo> sendRequestVo = new SendRequestVo<>();
		UpdateUserVo updateUserVo = new UpdateUserVo();
		sendRequestVo.setData(updateUserVo);
		sendRequestVo.setDeviceid(prDeviceEntity.getDevSign());
		sendRequestVo.setType("send");
		sendRequestVo.setCmdtype("17");
		String tic = String.format(devTopic, prDeviceEntity.getDevSign());
		mqttMessageSender.send(prDeviceEntity.getDevSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
		//同步用户与标签信息
		sendRequestVo.setCmdtype("19");
		mqttMessageSender.send(prDeviceEntity.getDevSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
		return R.ok();
	}
	private final PrRfidLogService prRfidLogService;
	/**
	 * 取出钥匙
	 * @param id 标签id
	 * @return
	 */
	@GetMapping("take/out")
	@SysLog("取出钥匙" )
	public R takeOut(@RequestParam String id) {
		//保存当前用户
		//获取设备sign
		PrRfidEntity prRfid = prRfidService.getById(id);

		//当前设备是否在线
		EmqxClientQueryDto emqxClientQueryDto = new EmqxClientQueryDto();
		EmqxDataVo<MqttClientStats> mqttClientStats = emqFeignClient.getMqttClientStats(emqxClientQueryDto);
		List<String> clientIdList = mqttClientStats.getData().stream().filter(MqttClientStats::getConnected).map(MqttClientStats::getClientid).collect(Collectors.toList());
		if(!clientIdList.contains(prRfid.getDeviceSign())){
			return R.result(null,500,"当前设备不在线");
		}

		SendRequestVo<TakeOutVo> sendRequestVo = new SendRequestVo<>();
		TakeOutVo takeOutVo = new  TakeOutVo();
		sendRequestVo.setDeviceid(prRfid.getDeviceSign());
		sendRequestVo.setType("send");
		sendRequestVo.setCmdtype("05");
		//需要打开的钥匙
		List<String> keys = new ArrayList<>();
		keys.add(prRfid.getRfidNum());
		takeOutVo.setKeys(keys);
		//获取当前用户绑定的柜体用户
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(SysUser::getUsername, authentication.getName());
		SysUser user = sysUserService.getOne(queryWrapper);
		UserVO userVO = sysUserMapper.getUserVoById(user.getUserId());
		JSONArray prUser = userVO.getPrUser();
		if(null == prUser){
			return R.failed("当前用户未绑定柜体");
		}
		String userId = "";
		for (int i = 0; i < prUser.size(); i++) {
			JSONArray pu = prUser.getJSONArray(i);
			String deviceSign = pu.getString(0);
			if(prRfid.getDeviceSign().equals(deviceSign)){
				userId = pu.getString(1);
			}

		}
		takeOutVo.setUserId(userId);
		takeOutVo.setDeviceid(prRfid.getDeviceSign());
		takeOutVo.setDevicename(prRfid.getDeviveName());
		sendRequestVo.setData(takeOutVo);
		String tic = String.format(devTopic, prRfid.getDeviceSign());
		mqttMessageSender.send(prRfid.getDeviceSign(),tic,0, JSONObject.toJSONString(sendRequestVo));
		//获取柜体用户信息
		QueryWrapper<PrUserEntity> prUserEntityQueryWrapper = new QueryWrapper<>();
		prUserEntityQueryWrapper.lambda().eq(PrUserEntity::getUserId, userId).eq(PrUserEntity::getDeviceSign,prRfid.getDeviceSign());
		PrUserEntity prUserEntity = prUserService.getOne(prUserEntityQueryWrapper);

		//记录日志
		PrRfidLogEntity prRfidLogEntity = new PrRfidLogEntity();
		prRfidLogEntity.setTakeStatus("1");
		prRfidLogEntity.setOperateType("1");
		prRfidLogEntity.setRfidName(prRfid.getRfidName());
		prRfidLogEntity.setRfidColumn(prRfid.getRfidColumn());
		prRfidLogEntity.setRfidNum(prRfid.getRfidNum());
		prRfidLogEntity.setDeviceSign(prRfid.getDeviceSign());
		prRfidLogEntity.setDeviceId(prRfid.getDeviceId());
		prRfidLogEntity.setDeviceName(prRfid.getDeviveName());
		prRfidLogEntity.setRfidNum(prRfid.getRfidNum());
		prRfidLogEntity.setOperateStatus("00");
		prRfidLogEntity.setGoodsId(prRfid.getGoodsId());
		prRfidLogEntity.setUserId(userId);
		prRfidLogEntity.setUserName(prUserEntity.getUserName());
		prRfidLogEntity.setRealName(prUserEntity.getRealName());
		prRfidLogService.save(prRfidLogEntity);
		return R.ok();
	}
}
